import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Properties;

public class Template {
    public static void main(String[] args) throws Exception {
        JdbcTemplate template = new JdbcTemplate(createDataSource());
        String sql = "select * from Student";
        List<Map<String, Object>> maps = template.queryForList(sql);
        System.out.println(maps);
    }
    public static void main1(String[] args) throws Exception {
        JdbcTemplate template = new JdbcTemplate(createDataSource());
        System.out.println(template);
        String sql = "insert into student values (? , ?)" ;
        template.update(sql , 1  , "张三");
        template.update(sql , 2 ,"李四");


    }

    public static DataSource createDataSource () throws Exception {
        Properties properties = new Properties();
        InputStream resourceAsStream = Template.class.getResourceAsStream("druid/druid-config.properties");

        properties.load(resourceAsStream);
        DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
        return dataSource;
    }
}
